<template>
  <el-dialog
    :title="title"
    :visible="props.visible"
    width="60%"
    center
    :before-close="handleClose"
  >
    <el-form :model="localForm" ref="ruleForm" label-width="auto">
      <el-row :gutter="50">
        <el-col :span="span" v-for="(item, index) in label" :key="index">
          <el-form-item
            :label="item.label"
            v-if="item.columnType === 'slot'"
            :prop="item.prop"
          >
            <slot :name="item.slotName" :params="{ row: localForm }"></slot>
          </el-form-item>
          <el-form-item v-else :label="item.label" :prop="item.prop">
            <el-input
              v-model="localForm[item.prop]"
              :placeholder="'请输入' + item.label"
            >
            </el-input>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitSecurity()">确 定</el-button>
      <el-button @click="disVisible()">取 消</el-button>
    </span>
  </el-dialog>
</template>

<script setup>
import { defineProps, defineEmits, ref, toRefs } from "vue";
const ruleForm = ref({});
const list = ref([]);
const props = defineProps({
  Form: {
    type: Object,
    default: () => {},
  },
  // 标题列表
  label: {
    type: Array,
    default: () => [],
  },
  data: {
    type: Array,
    default: () => [],
  },
  visible: {
    type: Boolean,
    default: false,
  },
  title: {
    type: String,
    default: "信息填写",
  },
  span: {
    type: Number,
    default: 6,
  },
});
const handleClose = () => {
  emit("disVisible");
};
// 使用 toRefs 来确保 localForm 是响应式的，并且分别响应 Form 的每一个属性
const { Form } = toRefs(props);
const localForm = Form;

console.log(props, list);
const emit = defineEmits(["submitSecurity", "disVisible"]);
const submitSecurity = () => {
  emit("submitSecurity", localForm);
};
const disVisible = () => {
  emit("disVisible");
};
</script>
